﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Hocky
    {
        public DataTable GetAll_Hocky()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select HocKyID,TenHocKy,GhiChu,isChangeable from DM_HocKy");
            return dataTable;
        }
        public bool Insert(clsDM_Hocky obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HocKyID", obj.HocKyID);
                db.AddParameter("@TenHocKy", obj.TenHocKy);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_HocKy(TenHocKy,GhiChu,isChangeable) values(N'" + obj.TenHocKy + "',N'" + obj.GhiChu + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Hocky obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HocKyID", obj.HocKyID);
                db.AddParameter("@TenHocKy", obj.TenHocKy);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_HocKy set TenHocKy=N'" + obj.TenHocKy + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where HocKyID='" + obj.HocKyID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Hockyid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@HocKyID", Hockyid);
                db.ExecuteNonQuery("delete DM_HocKy where HocKyID='" + Hockyid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
